<template>
	<view class="container">
		<scroll-view scroll-y class="content">
			<view>
				<!-- 用户 -->
				<view class="user-list">
					<view class="header">
						<image :src="userImg" mode=""></image>
						<text>沐歌</text>
					</view>
					<view class="user-text">
						1、赵子龙，参见!(登场)
						2、一鼓作气，进击!(登场)
						3、枪如惊雷，照一身肝胆!(登场)
						4、枪尖在燃烧!
						5、心怀不惧，方能翱翔于天际!
						6、阁下的首级，我收下了!
						7、抱歉，你挡路了! (挑衅)
						8、勇者之事，甚于生死!
						9、看清楚了吗，这贯穿乱世的雷霆!
						10、雷霆万钧。
						11、七进七出。
						12、龙枪乱舞，万夫莫敌!
						13、拜托……各位了……(死亡)
						14、主公，为你而战!
						15、胜负已分!
						16、人气太高，也是一种困扰~(嗯?)
					</view>
				</view>
				<!-- 客服 -->
				<view class="service-list" v-for="(item,index) in 2" :key="index">
					<view class="header">
						<text>可爱小姐姐</text>
						<image :src="sercviceImg" mode=""></image>
					</view>
					<view class="user-text">
						1、赵子龙，参见!(登场)
						2、人气太高，也是一种困扰~(嗯?)
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="send">
			<view class="input">
				<u-input placeholderStyle="padding-left: 15px" class="input-style" v-model="value" />
			</view>
			<view class="btn">
				<u-button @click="send" class="btn-style" type="success" :ripple="true">发送</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import api from 'common/api.js'
	export default {
		data() {
			return {
				list: [{
						id: 1,
						time: '11:02:01',
						content: '美女，给个微信号呗~',
						type: 1,
						name:'沐歌'
					},
					{
						id: 2,
						time: '12:12:14',
						content: '好不好嘛~',
						type: 1,
						name:'沐歌'
					},
					{
						id: 3,
						time: '12:14:1',
						content: '好呀~',
						type: 0,
						name:'可爱小姐姐'
					},
				],
				value: '',
				name:'沐歌',
				sercviceImg:'../../static/service/service.jpg',
				userImg:'../../static/service/user.jpg'
			};
		},
		methods: {
			send() {
				this.$goEasy.publish({
					channel: "muxi", 
					message: this.value
				});
				console.log(this.value);
				// let obj = {}
				// obj.id = this.list.length+1
				// obj.name=this.name
				// obj.type=1
				// obj.time=new Date().getTime()
				// obj.content=this.value
				// this.list.push(obj)
			}
		},
		onLoad() {
			// uni.request({
			// 	method:'GET',
			// 	url:"http://localhost:3000/getUserChat",
			// 	success: (res) => {
			// 		console.log(res);
			// 	}
			// })
			this.$goEasy.subscribe({
				channel: "muge", 
				onMessage: message => {
					console.log(message,'客服，监听');
					// let obj = {}
					// obj.id = this.list.length+1
					// obj.name='可爱小姐姐'
					// obj.type=0
					// obj.time=message.time
					// obj.content=message.content
					// console.log(obj,'客服');
					// this.list.push(obj)
				}
			});
		}

	}
</script>


<style lang="less">
	.container {
		height: calc(100vh - 176rpx);
		width: 100%;
		box-sizing: border-box;
		// uview 输入框样式重置
		/deep/.uni-input-input{
			padding-left: 15px;
		}
		.content {
			height: calc(100vh - 176rpx);
			width: 100%;
			padding: 20rpx;
			overflow: auto;
			box-sizing: border-box;
			background-color: #EEEEEE;

			.user-list {
				width: 100%;
				margin-bottom: 10rpx;
				.header {
					display: flex;
					align-items: center;
					justify-content: flex-start;

					>text {
						font-size: 28rpx;
						color: rgba(0, 0, 0, .7);
						font-weight: 700;
						margin-left: 20rpx;
					}

					>image {
						height: 80rpx;
						width: 80rpx;
						border-radius: 50%;
					}
				}

				.user-text {
					border-radius: 25rpx;
					padding: 15rpx;
					margin: 0 auto;
					max-width: 600rpx;
					font-size: 26rpx;
					line-height: 40rpx;
					background-color: #fff;
				}
			}

			.service-list {
				width: 100%;
				margin-bottom: 10rpx;

				.header {
					display: flex;
					align-items: center;
					justify-content: flex-end;

					>text {
						font-size: 28rpx;
						color: rgba(0, 0, 0, .7);
						font-weight: 700;
						margin-right: 20rpx;
					}

					>image {
						height: 80rpx;
						width: 80rpx;
						border-radius: 50%;
					}
				}

				.user-text {
					border-radius: 25rpx;
					padding: 15rpx;
					margin: 0 auto;
					max-width: 600rpx;
					font-size: 26rpx;
					line-height: 40rpx;
					background-color: #FFFFFF;
				}
			}
		}

		.send {
			height: 88rpx;
			width: 100%;
			display: flex;
			justify-content: space-between;
			padding: 0 20rpx;
			align-items: center;
			background-color: rgba(238,238,238,.6);

			.input {
				width: 80%;
				border-radius: 10rpx;
				background-color: #fff;

				.input-style {
					padding: 0 20rpx;
				}
			}

			.btn {
				display: flex;
				align-items: center;
				height: 80rpx;
				width: 15%;
				text-align: center;
				border-radius: 10rpx;

				.btn-style {
					height: 70rpx;
				}
			}

		}
	}
</style>
